#ifndef __ACTOR_H__
#define __ACTOR_H__

#include <directfb.h>
#include <direct/direct.h>
#include "dtk_list.h"
#include "dtk_types.h"
#include "dtk_object.h"
#include "dtk_signal_manage.h"
#include "dtk_property.h"
#include "dtk_event.h"
#include "dtk_layout.h"


typedef enum {
  DTK_ACTOR_UNUSED_FLAG    = 0,

  DTK_ACTOR_IN_DESTRUCTION = 1 << 0,
  DTK_ACTOR_IS_TOPLEVEL    = 1 << 1,
  DTK_ACTOR_IN_REPARENT    = 1 << 2,

  /* Used by the stage to indicate GL viewport / perspective etc needs
   * (re)setting.
   */
  DTK_ACTOR_SYNC_MATRICES  = 1 << 3,

  /* Used to avoid recursion */
  DTK_ACTOR_IN_PAINT       = 1 << 4,

  /* Used to avoid recursion */
  DTK_ACTOR_IN_RELAYOUT    = 1 << 5,

  /* Used by the stage if resizing is an asynchronous operation (like on
   * X11) to delay queueing relayouts until we got a notification from the
   * event handling
   */
  DTK_STAGE_IN_RESIZE      = 1 << 6,

  /* a flag for internal children of Containers */
  DTK_ACTOR_INTERNAL_CHILD = 1 << 7
} DTKPrivateFlags;

typedef struct _actor_process
{
    void (*add)         (DTKActor* self, DTKActor* actor);
    void (*remove)         (DTKActor* self, DTKActor* actor);
    void (*show)        (DTKActor* actor);
    void (*show_all)    (DTKActor* actor);
    void (*hide)        (DTKActor* actor);
    void (*hide_all)    (DTKActor* actor);
    void (*draw)        (DTKActor* actor, DTKGC* gc, DRegion* region);

    void (*button_down)  (DTKActor* self, DTKMouseButtonEventArgs* ev);
    void (*button_up)    (DTKActor* self, DTKMouseButtonEventArgs* ev);

    void (*release)     (DTKActor* actor);
    IDirectFBSurface*   (*get_surface) (DTKActor* actor);
    
}DTKActorCallback;

struct _dtk_actor
{
    DTKObject           base;

    DLink               link;

    DBoolean            is_initialized;
    DString             type;

    DTKActorCaps        caps;
    
    DRectangle          rect;
    DPoint              abs_point;
    DTKPrivateFlags     flags;
    DInt                opacity;
    DBoolean            visible;
    DColor              bgcolor;

    DString             name;
    DUInt               id;
    DTKActor*           parent;
    DTKLayout*          layout;
    IDirectFBSurface*   surface;
    DTKActorCallback    funcs;
};



#define DTK_ACTOR(x) ((DTKActor*)(x))
#define DTK_ACTOR_CALLBACK(x) (&((x)->funcs))
#define DTK_ACTOR_LINK(x) ((x)->link)
#define DTK_ACTOR_CONTAINER ((x)->container);

#endif
